/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entityBeans;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
//import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;


/**
 *
 * @author user
 */
@Entity
@Table(name = "user")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"),
    @NamedQuery(name = "User.findByUserID", query = "SELECT u FROM User u WHERE u.userID = :userID"),
    @NamedQuery(name = "User.findByName", query = "SELECT u FROM User u WHERE u.name = :name"),
    @NamedQuery(name = "User.findBySurname", query = "SELECT u FROM User u WHERE u.surname = :surname"),
    @NamedQuery(name = "User.findByGender", query = "SELECT u FROM User u WHERE u.gender = :gender"),
    @NamedQuery(name = "User.findByEmail", query = "SELECT u FROM User u WHERE u.email = :email"),
    @NamedQuery(name = "User.findByCity", query = "SELECT u FROM User u WHERE u.city = :city"),
    @NamedQuery(name = "User.findByJob", query = "SELECT u FROM User u WHERE u.job = :job"),
    @NamedQuery(name = "User.findByBday", query = "SELECT u FROM User u WHERE u.bday = :bday"),
    @NamedQuery(name = "User.findByPassword", query = "SELECT u FROM User u WHERE u.password = :password")})
public class User implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "User_ID")
    private String userID;
    //@Size(max = 20)
    @Column(name = "Name")
    private String name;
    //@Size(max = 20)
    @Column(name = "Surname")
    private String surname;
    //@Size(max = 20)
    @Column(name = "Gender")
    private String gender;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    //@Size(max = 40)
    @Column(name = "E_mail")
    private String email;
    //@Size(max = 20)
    @Column(name = "City")
    private String city;
    //@Size(max = 20)
    @Column(name = "Job")
    private String job;
    //@Size(max = 20)
    @Column(name = "B_day")
    private String bday;
 
    @Column(name = "Password")
    private String password;
    
    @OneToMany(mappedBy = "userCollection")
    private Collection<RequestNotification> requestNotificationCollection;
    
    @JoinTable(name = "sendmessage", joinColumns = {
        @JoinColumn(name = "User_ID", referencedColumnName = "User_ID")}, inverseJoinColumns = {
        @JoinColumn(name = "M_ID", referencedColumnName = "M_ID")})
    @OneToMany
    private Collection<Message> messageCollection;
    
    @JoinTable(name = "participates", joinColumns = {
        @JoinColumn(name = "User_ID", referencedColumnName = "User_ID")}, inverseJoinColumns = {
        @JoinColumn(name = "Meeting_ID", referencedColumnName = "Meeting_ID")})
    @ManyToMany
    private Collection<Helpmeeting> helpmeetingCollection;
    
    @ManyToMany(mappedBy = "userCollection")
    private Collection<Ability> abilityCollection;
    
    @JoinTable(name = "friendship", joinColumns = {
        @JoinColumn(name = "UserA_ID", referencedColumnName = "User_ID")}, inverseJoinColumns = {
        @JoinColumn(name = "UserB_ID", referencedColumnName = "User_ID")})
    @ManyToMany
    private Collection<User> userCollection;
    

    
    @OneToMany(mappedBy = "userCollection")
    private Collection<Comment> commentCollection;

    public User() {
    }

    public User(String userID) {
        this.userID = userID;
    }

    public String getUserID() {
        return userID;
    }

    public void setUserID(String userID) {
        this.userID = userID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public String getBday() {
        return bday;
    }

    public void setBday(String bday) {
        this.bday = bday;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password2) {
        this.password = password2;
    }

    @XmlTransient
    public Collection<RequestNotification> getRequestNotificationCollection() {
        return requestNotificationCollection;
    }

    public void setRequestNotificationCollection(Collection<RequestNotification> requestNotificationCollection) {
        this.requestNotificationCollection = requestNotificationCollection;
    }

    @XmlTransient
    public Collection<Message> getMessageCollection() {
        return messageCollection;
    }

    public void setMessageCollection(Collection<Message> messageCollection) {
        this.messageCollection = messageCollection;
    }

    @XmlTransient
    public Collection<Helpmeeting> getHelpmeetingCollection() {
        return helpmeetingCollection;
    }

    public void setHelpmeetingCollection(Collection<Helpmeeting> helpmeetingCollection) {
        this.helpmeetingCollection = helpmeetingCollection;
    }

    @XmlTransient
    public Collection<Ability> getAbilityCollection() {
        return abilityCollection;
    }

    public void setAbilityCollection(Collection<Ability> abilityCollection) {
        this.abilityCollection = abilityCollection;
    }

    @XmlTransient
    public Collection<User> getUserCollection() {
        return userCollection;
    }

    public void setUserCollection(Collection<User> userCollection) {
        this.userCollection = userCollection;
    }

//    @XmlTransient
//    public Collection<User> getUserCollection1() {
//        return userCollection1;
//    }
//
//    public void setUserCollection1(Collection<User> userCollection1) {
//        this.userCollection1 = userCollection1;
//    }

    @XmlTransient
    public Collection<Comment> getCommentCollection() {
        return commentCollection;
    }

    public void setCommentCollection(Collection<Comment> commentCollection) {
        this.commentCollection = commentCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userID != null ? userID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.userID == null && other.userID != null) || (this.userID != null && !this.userID.equals(other.userID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "swimtwo.entityBeans.User[ userID=" + userID + " ]";
    }
    
}